library(lme4)
library(stargazer)
library(performance)

load("../Data/Referees.RData")

################################################################################
# Basic models

nm.hms <- lmer(deltaProp19.20 ~ Women1 * TimeSinceFirstPub + (1 | CountryCode), HMS)
nm.ls <- lmer(deltaProp19.20 ~ Women1 * TimeSinceFirstPub + (1 | CountryCode), LS)
nm.ps <- lmer(deltaProp19.20 ~ Women1 * TimeSinceFirstPub + (1 | CountryCode), PS)
nm.sse <- lmer(deltaProp19.20 ~ Women1 * TimeSinceFirstPub + (1 | CountryCode), SSE)

stargazer(nm.hms, nm.ls, nm.ps, nm.sse, report="vcsp", object.names=T, model.numbers=F, digit.separate=0, type="text")

stargazer(nm.hms, nm.ls, nm.ps, nm.sse, report="vcsp", object.names=T, model.numbers=F, digit.separate=0, covariate.labels=c("Women", "Academic age", "Women$\\times$Academic age",  "Intercept"), type="latex")

################################################################################
# Mobility models

load("../Data/MobilityData.RData")

mobility$week <- lubridate::week(mobility$date)
summary(mobility)
startW <- 6
stopW <- 22
cov.ag <- aggregate(cbind(workplaces,residential) ~ iso3c, data=subset(mobility, week >= startW & week <= stopW), FUN=base::mean)

HMS <- merge(HMS, cov.ag, by.x="CountryCode", by.y="iso3c", all.x=T)
LS <- merge(LS, cov.ag, by.x="CountryCode", by.y="iso3c", all.x=T)
PS <- merge(PS, cov.ag, by.x="CountryCode", by.y="iso3c", all.x=T)
SSE <- merge(SSE, cov.ag, by.x="CountryCode", by.y="iso3c", all.x=T)

m.hms <- lmer(deltaProp19.20 ~ Women1*TimeSinceFirstPub + Women1*residential + (1 | CountryCode), HMS)
m.ls <- lmer(deltaProp19.20 ~ Women1*TimeSinceFirstPub + Women1*residential + (1 | CountryCode), LS)
m.ps <- lmer(deltaProp19.20 ~ Women1*TimeSinceFirstPub + Women1*residential + (1 | CountryCode), PS)
m.sse <- lmer(deltaProp19.20 ~ Women1*TimeSinceFirstPub + Women1*residential + (1 | CountryCode), SSE)

stargazer(m.hms, m.ls, m.ps, m.sse, report="vcsp", object.names=T, model.numbers=F, digit.separate=0, type="text")

stargazer(m.hms, m.ls, m.ps, m.sse, report="vcsp", object.names=T, model.numbers=F, digit.separate=0, covariate.labels=c("Women", "Academic age", "Residential","Women$\\times$Academic age", "Women$\\times$Residential","Intercept"), type="latex")


################################################################################
# Women2 models
nm.hms <- lmer(deltaProp19.20 ~ Women2 * TimeSinceFirstPub + (1 | CountryCode), HMS)
nm.ls <- lmer(deltaProp19.20 ~ Women2 * TimeSinceFirstPub + (1 | CountryCode), LS)
nm.ps <- lmer(deltaProp19.20 ~ Women2 * TimeSinceFirstPub + (1 | CountryCode), PS)
nm.sse <- lmer(deltaProp19.20 ~ Women2 * TimeSinceFirstPub + (1 | CountryCode), SSE)

stargazer(nm.hms, nm.ls, nm.ps, nm.sse, report="vcsp", object.names=T, model.numbers=F, digit.separate=0, type="text")

stargazer(nm.hms, nm.ls, nm.ps, nm.sse, report="vcsp", object.names=T, model.numbers=F, digit.separate=0, covariate.labels=c("Women", "Academic age", "Women$\\times$Academic age",  "Intercept"), type="latex")


